<?php
/**
 * This is users/admin_edit template file. 
 *
 * @copyright     Copyright 2008-2010, LilCake.net
 * @link          http://lilcake.net LilCake.net
 * @package       lil
 * @subpackage    lil.views.users
 * @license       MIT License (http://www.opensource.org/licenses/mit-license.php)
 */
	$user_edit = array(
		'title_for_layout' => __d('lil', 'Edit User', true),
		'title' => 	'<div class="head">'.
			'<h1>' . __d('lil', 'Edit User', true) . '</h1>'.
			'</div>',
		'form' => array(
			'pre' => '<div class="form">',
			'post' => '</div>',
			'lines' => array(
				'form_start' => array(
					'class'      => $this->Form,
					'method'     => 'create',
					'parameters' => array('model' => 'User')
				),
				'id' => array(
					'class'      => $this->Form,
					'method'     => 'hidden',
					'parameters' => array('field' => 'id')
				),
				'referer' => array(
					'class'      => $this->Form,
					'method'     => 'hidden',
					'parameters' => array('field' => 'referer')
				),
				'name' => array(
					'class'      => $this->Form,
					'method'     => 'input',
					'parameters' => array(
						'field'   => Configure::read('Lil.userDisplayField'),
						'options' => array(
							'label' => __d('lil', 'Name', true) . ':',
							'error' => __d('lil', 'User\'s name is required.', true),
							'class' => 'big'
						)
					)
				),
				'username' => array(
					'class'      => $this->Form,
					'method'     => 'input',
					'parameters' => array(
						'field'   => 'username',
						'options' => array(
							'label' => __d('lil', 'Username', true) . ':',
							'error' => __d('lil', 'Username is required, format must be valid.', true),
						)
					)
				),
				'passwords' => array(
					'class'      => $this->Form,
					'method'     => 'inputs',
					'parameters' => array(
						'inputs' => array(
							'legend' => __d('lil', 'Change password', true),
							'passwd' => array(
								'label' => __d('lil', 'New password', true) . ':',
								'error' => __d('lil', 'Password is required, format must be valid.', true),
							),
							'new_pass' => array(
								'type'  => 'password',
								'label' => __d('lil', 'Repeat password', true) . ':',
								'error' => __d('lil', 'Passwords do not match.', true),
							),
						)
					)
				),
				// display areas only if user is not administrator
				'areas' => ((bool)$this->Html->value('User.' . Configure::read('Lil.userAdminField')) || empty($areas)) ? null : array(
					'class'      => $this->Form,
					'method'     => 'inputs',
					'parameters' => array(
						'inputs' => array(
							'legend' => __d('lil', 'User Areas', true),
							'Area.Area' => array(
								'label' => __d('lil', 'Select areas', true) . ':',
							),
						)
					)
				),
				'submit' => array(
					'class'      => $this->Form,
					'method'     => 'submit',
					'parameters' => array(
						'label' => __d('lil', 'Save', true)
					)
				),
				'form_end' => array(
					'class'      => $this->Form,
					'method'     => 'end',
					'parameters' => array()
				),
			)
		)
	);
	
	$user_edit = $this->callPluginHandlers('form_edit_user', $user_edit);
	
	$this->set('title_for_layout', $user_edit['title_for_layout']);
	
	// form display begins
	echo $user_edit['title']; 
	
	echo $user_edit['form']['pre']; 
	foreach ($user_edit['form']['lines'] as $name => $line) {
		if (is_string($line)) {
			echo $line;
		} else if (!empty($line['class'])) {
			$parameters = array();
			if (!empty($line['parameters'])) {
				$parameters = (array)$line['parameters'];
			}
			if (is_object($line['class'])) {
				$use_object =& $line['class'];
			} else {
				$use_object =& ${$line['class']};
			}
			echo call_user_func_array(array($use_object, $line['method']), $parameters);
		}
	}
	echo $user_edit['form']['post']; 